﻿@model SIG.Model.DTO.ProductPageMetaDTO

@{
    ViewBag.Title = "编辑产品";
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
   
}
@section Header{

<link href="~/Content/Plugins/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet" />
<script src="~/Areas/Admin/Content/Plugins/ckeditor/ckeditor.js"></script>
<script src="~/Areas/Admin/Content/Plugins/ckfinder/ckfinder.js"></script>
}

@section leftNav{
    @Html.Partial("_NavForContent")
}



<div class="main-content">

@using (Ajax.BeginForm("EditProduct", null, new AjaxOptions()
{

    LoadingElementId = "saving",
    LoadingElementDuration = 2000,
    //   Confirm = "Are you sure you want to save this User?"
    OnSuccess = "updateSuccess"

}, new { @class = "form-horizontal", role = "form" }))
{

    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.CreatedBy)
    @Html.HiddenFor(model => model.CreatedDate)
    @Html.HiddenFor(model => model.UpdatedBy)
    @Html.HiddenFor(model => model.UpdatedDate)


    <div class="panel panel-default sig-panel-tabs">
        <header class="panel-heading">            
          <h3 class="panel-title">@ViewBag.Title</h3>
        </header>

        <section class="panel-body">
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#product" aria-controls="product" role="tab" data-toggle="tab">@ViewBag.Title</a></li>
                <li role="presentation"><a href="#seo" aria-controls="seo" role="tab" data-toggle="tab">SEO设置</a></li>
            </ul>
            <!-- Tab panes -->
            <div class="tab-content" style="padding-top:30px;">
                <div role="tabpanel" class="tab-pane active" id="product">

                    <div class="form-group">
                        @Html.LabelFor(model => model.ProductNo, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            @Html.TextBoxFor(model => model.ProductNo, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ProductNo, ViewData).Watermark })
                            @Html.ValidationMessageFor(model => model.ProductNo)
                        </div>

                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.ProductName, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            @Html.TextBoxFor(model => model.ProductName, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ProductName, ViewData).Watermark })
                            @Html.ValidationMessageFor(model => model.ProductName)
                        </div>

                    </div>


                    <div class="form-group">
                        @Html.LabelFor(model => model.PostCategoryIds, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            @Html.ListBoxFor(model => model.PostCategoryIds, (List<SelectListItem>)ViewBag.Categories, new { @class = "form-control selectpicker" })


                        </div>
                        <div class="col-md-5">@Html.ValidationMessageFor(model => model.PostCategoryIds)</div>
                    </div>



                    <div class="form-group">
                        @Html.LabelFor(model => model.Thumbnail, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            <div class="input-group">
                                @Html.TextBoxFor(model => model.Thumbnail, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Thumbnail, ViewData).Watermark })
                                <span class="input-group-btn">
                                    <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                                </span>
                            </div><!-- /input-group -->
                            <span class="help-block">图片大小为：300x300像素</span>
                        </div>
                        <div class="col-md-5">
                            @Html.ValidationMessageFor(model => model.Thumbnail)
                        </div>
                    </div>

                    @*<div class="form-group">
                    @Html.LabelFor(model => model.ImageUrl, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.ImageUrl, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ImageUrl, ViewData).Watermark })
                            <span class="input-group-btn">
                                <button class="btn btn-default" id="btnImageUrl" type="button">浏览…</button>
                            </span>
                        </div> /input-group
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.ImageUrl)
                    </div>
                </div>*@

                    <div class="form-group">
                        @Html.LabelFor(model => model.Body, new { @class = "col-md-2 control-label" })
                        <div class="col-md-10">
                            @Html.TextAreaFor(model => model.Body, new { @class = "form-control", placeholder = "描述" })
                            @Html.ValidationMessageFor(model => model.Body)
                        </div>

                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.Description, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            @Html.TextAreaFor(model => model.Description, new { @class = "form-control", placeholder = "摘要" })
                        </div>
                        <div class="col-md-5">
                            @Html.ValidationMessageFor(model => model.Description)
                        </div>
                    </div>


                  


                    <div class="form-group">
                        <div class="col-md-10 col-md-offset-2">
                            <div class="checkbox">
                                <label>
                                    @Html.CheckBoxFor(model => model.Recommend)  @Html.DisplayNameFor(model => model.Recommend)  @Html.ValidationMessageFor(model => model.Recommend)
                                </label>
                            </div>
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-md-10 col-md-offset-2">
                            <div class="checkbox">
                                <label>
                                    @Html.CheckBoxFor(model => model.Active)  @Html.DisplayNameFor(model => model.Active)  @Html.ValidationMessageFor(model => model.Active)
                                </label>
                            </div>
                        </div>
                    </div>

                </div>
                <div role="tabpanel" class="tab-pane" id="seo">

                    <div class="form-group">
                        @Html.LabelFor(model => model.Keywords, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            @Html.TextBoxFor(model => model.Keywords, new { @class = "form-control", placeholder = "关键字(SEO)" })
                        </div>
                        <div class="col-md-5">
                            @Html.ValidationMessageFor(model => model.Keywords)
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.SEODescription, new { @class = "col-md-2 control-label" })
                        <div class="col-md-5">
                            @Html.TextAreaFor(model => model.SEODescription, new { @class = "form-control", placeholder = "描述(SEO)" })
                        </div>
                        <div class="col-md-5">
                            @Html.ValidationMessageFor(model => model.SEODescription)
                        </div>
                    </div>

                </div>
            </div><!-- /.tab-content -->
        </section>
        <footer class="panel-footer text-right">
            <input type="submit" class="btn btn-primary" value="编辑产品" /> <a href="@Url.Action("Index")" class="btn btn-default">返回</a>
        </footer>

    </div>

}
</div>


@section Footer {
    @Scripts.Render("~/bundles/jqueryval")
<script src="~/Content/Plugins/bootstrap-select/js/bootstrap-select.min.js"></script>
<script src="~/Content/Plugins/bootstrap-select/js/i18n/defaults-zh_CN.min.js"></script>


    <script>
        var editor = CKEDITOR.replace("Body", {
            filebrowserImageBrowseUrl: '/plugins/ckfinder/ckfinder.html?type=Images',
            filebrowserUploadUrl: '/plugins/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files',
            filebrowserImageUploadUrl: '@Url.Content("~/Content/Uploads")'
        }
            );
        CKFinder.setupCKEditor(editor, '@Url.Content("~/plugins/ckfinder/")');


    function SetThumbnail(fileUrl) {
        $('#Thumbnail').val(fileUrl);
    }

    function SetImageUrl(fileUrl) {
        $('#ImageUrl').val(fileUrl);
    }

     function updateSuccess(result) {


        //  console.log(data.Oicq);
        toastr.options = {
            "positionClass": "toast-bottom-full-width"
        }
        if (result.Status) {
            toastr.success(result.Message, '@ViewBag.Title');
        } else {
            toastr.error(result.Message, '@ViewBag.Title');
        }


    }



    $(function () {
        $("#btnThumbnail").on("click", function () {
            var finder = new CKFinder();
            //  finder.basePath = '/plugins/ckfinder/';
            finder.selectActionFunction = SetThumbnail;
            finder.popup();
        });

        $("#btnImageUrl").on("click", function () {
            var finder = new CKFinder();
            finder.selectActionFunction = SetImageUrl;
            finder.popup();
        });

        //当前菜单
        $('.mainmenu>li').eq(0).addClass('nav-open').find('.submenu li:nth-of-type(1)').children('a').addClass('active');

        //转换boostrap 验证
        $('span.field-validation-valid, span.field-validation-error').each(function () {
              $(this).addClass('help-block');
        });

             var $form = $('form');
             var $validate = $form.validate();
             var errorClass = "has-error";
             //var successClass = "has-success";
             $validate.settings.errorClass = errorClass;
             var previousEPMethod = $validate.settings.errorPlacement;
             $validate.settings.errorPlacement = $.proxy(function (error, inputElement) {
                     if (previousEPMethod) {
                             previousEPMethod(error, inputElement);
                         }
                     inputElement.parent().addClass(errorClass)
                 }, $form[0]);

             var previousSuccessMethod = $validate.settings.success;
             $validate.settings.success = $.proxy(function (error) {
                     //we first need to remove the class, cause the unobtrusive success method removes the node altogether
                 error.parent().parent().removeClass(errorClass)
                     if (previousSuccessMethod) {
                             previousSuccessMethod(error);
                         }
                 });


        });
    </script>
}
